
#include "Grid.hpp"

using namespace Gomoku::UI;

Grid::Grid()
{

}

Grid::~Grid()
{

}

void Grid::draw(sf::RenderWindow& window)
{
	std::list<sf::Shape>::iterator ite = this->_gridLines.end();
	for (std::list<sf::Shape>::iterator it = this->_gridLines.begin(); it != ite; ++it)
		window.Draw(*it);
}

void Grid::generate(unsigned int gridSize, unsigned int windowSize)
{
	this->_gridLines.clear();
	if (gridSize != 0)
	{
		float blockSize = static_cast<float>(windowSize) / static_cast<float>(gridSize);
		if (blockSize > 1)
		{
			for (float i = blockSize / 2; i < windowSize && i / blockSize < gridSize; i += blockSize)
			{
				this->_gridLines.push_back(sf::Shape::Line(i, 0, i, gridSize * blockSize, 5, sf::Color(255, 255, 255)));
				this->_gridLines.push_back(sf::Shape::Line(0, i, gridSize * blockSize, i, 5, sf::Color(255, 255, 255)));
			}				
		}
	}
}